function display(ti)
% transimg::display  - display an image

% Version:  v0.8a
% Build:    9112017
% Date:     Nov-20 2009, 5:13 PM CET
% Author:   Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% global variables for storage
global tiobj ...
       tiobjlup;
   
% check arguments
lup = find(tiobjlup == ti.L);
if numel(lup) ~= 1
    error( ...
        'transimg:ObjectRemoved', ...
        'Object removed from global storage.' ...
    );
end

% only if width/height > 0
if any([tiobj(lup).Width, tiobj(lup).Height] == 0)
    return;
end

% which object
if isempty(tiobj(lup).Handle) || ...
   ~ishandle(tiobj(lup).Handle)
    f = figure;
    x = axes;
    tiobj(lup).Handle = image(tiobj(lup).Rendered);
    set(f, 'Units', 'pixels');
    fp = get(f, 'Position');
    fp(3:4) = [tiobj(lup).Width, tiobj(lup).Height];
    set(f, 'Position', fp);
    set(f, 'Units', 'normalized', 'NumberTitle', 'off', 'Name', ...
        sprintf('transimg: %d x %d', tiobj(lup).Width, tiobj(lup).Height));
    set(x, 'Position', [0, 0, 1, 1]);
else
    set(tiobj(lup).Handle, 'CData', tiobj(lup).Rendered);
end
